package org.webball.main;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.webball.base.interfaces.IController;
import org.webball.base.interfaces.IDraw;
import org.webball.communication.Communication;
import org.webball.controller.Controller;
import org.webball.draw.Draw;
import org.webball.pitch.Pitch;
import org.webball.pitch.Team;
import org.webball.player.Player;

/**
 * 
 * @author Elwira Kowalewska
 *
 */

public class Game extends BasicGame
{
	private Communication comm;
	private Pitch pitch;
	private Player[] players1;
	private IDraw d;
	private IController c;
	private Input input;
	private int myTeam = 0;			// testowo ustalamy team na 0
	
	
    public Game(String title, Communication comm, Player[] pl, int team)
    {
		super(title);
		this.comm = comm;
		this.players1 = pl;
		this.myTeam = team;
    }
    
    public void render(GameContainer container, Graphics g) throws SlickException
    {
    	d.draw(g, pitch);
	}
    
	public void init(GameContainer container) throws SlickException
	{
		pitch = new Pitch();
		
		Player[] players2 = new Player[6];
		for(int i=0; i<6; i++)
		{
			players2[i] = new Player();
		}
		
		pitch.setTeam(0, new Team(players1));
		pitch.setTeam(1, new Team(players2));
		
		d = new Draw(myTeam);			// klasa Kuby Garczynskiego
		c = new Controller();			// klasa Jacka Gawrona
	}
	
	public void update(GameContainer container, int delta) throws SlickException
	{
		input = container.getInput();
		c.setTeam(myTeam);
		c.action(pitch, input);
	}

}